<template>
  <div class="home">
    <el-container>
      <el-header>宏烨找房后台管理系统</el-header>
      <el-container>
        <el-aside width="200px">
          <div class="toggle-title">管理员</div>
          <el-menu
            :collapse-transition="false"
            text-color="#8b8d8f"
            unique-opened
            :router="true"
            active-text-color="#ffd04b"
            background-color="#001529"
            :default-active="activePath"
          >
            <el-menu-item
              :index="item.path"
              v-for="item in menuList"
              :key="item.id"
              @click="saveNavState(item.path)"
              ><template slot="title">
                <!-- 图标 -->
                <i class="el-icon-location"></i>
                <!-- 文本 -->
                <span>{{ item.authName }}</span>
              </template>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
      activePath: '',
      menuList: [
        {
          id: Math.random(),
          authName: '房源管理',
          path: '/housing'
        },
        {
          id: Math.random(),
          authName: '直播管理',
          path: '/live'
        },
        {
          id: Math.random(),
          authName: '团购管理',
          path: '/group'
        },
        {
          id: Math.random(),
          authName: '审核管理',
          path: '/audit'
        },
        {
          id: Math.random(),
          authName: '订单管理',
          path: '/order'
        },
        {
          id: Math.random(),
          authName: '资讯管理',
          path: '/information'
        },
        {
          id: Math.random(),
          authName: '经纪人管理',
          path: '/broker'
        }
      ]
    }
  },
  methods: {
    saveNavState (activePath) {
      sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  },
  created () {
    this.activePath = sessionStorage.getItem('activePath')
  }
}
</script>

<style scoped>
.toggle-title {
  background-color: #001529;
  font-size: 16px;
  line-height: 56px;
  color: #7d8184;
  text-align: center;
  cursor: pointer;
  letter-spacing: 0.2em;
}

.el-header {
  background-color: #4381e6;
  color: #fff;
  line-height: 60px;
  font-size: 20px;
  font-weight: bold;
}

.el-aside {
  background-color: #001529;
  color: #333;
  text-align: center;
  height: 700px;
  line-height: 200px;
}

.el-submenu__title {
  background: #001529;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
